<?php defined('BASEPATH') OR exit('No direct script access allowed');

	class exchange_item_class extends CI_Model {
	
		public function insert($post){
			$strItemCode = stripslashes(filter_var($post['strItemCode'], FILTER_SANITIZE_STRING));
			$strTitle = stripslashes(filter_var($post['strTitle'], FILTER_SANITIZE_STRING));
			$strDescription = stripslashes(filter_var($post['strDescription'], FILTER_SANITIZE_STRING));
			$intPoints = stripslashes(filter_var($post['intPoints'], FILTER_SANITIZE_STRING));
			$dateStart = stripslashes(filter_var($post['dateStart'], FILTER_SANITIZE_STRING));
			$dateEnd = stripslashes(filter_var($post['dateEnd'], FILTER_SANITIZE_STRING));
			$intQty = stripslashes(filter_var($post['intQty'], FILTER_SANITIZE_STRING));
				
			$data = array(
					'strItemCode' => $strItemCode,
					'strTitle' => $strTitle,
					'strDescription' => $strDescription,
					'intPoints' => $intPoints,
					'strImgLink' => $strImgLink,
					'dateStart' => $dateStart,
					'dateEnd' => $dateEnd,
					'intQty' => $intQty,
					'intDisabled' => 0,
					'strCreatedby'=>$this->session->userdata('intID'),
					'dateCreatedDate'=>date('Y-m-d H:i:s'),
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);

			$this->db->insert('jtn_exchange_item', $data);
			
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function update($post){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$strItemCode = stripslashes(filter_var($post['strItemCode'], FILTER_SANITIZE_STRING));
				$strTitle = stripslashes(filter_var($post['strTitle'], FILTER_SANITIZE_STRING));
				$strDescription = stripslashes(filter_var($post['strDescription'], FILTER_SANITIZE_STRING));
				$intPoints = stripslashes(filter_var($post['intPoints'], FILTER_SANITIZE_STRING));
				$dateStart = stripslashes(filter_var($post['dateStart'], FILTER_SANITIZE_STRING));
				$dateEnd = stripslashes(filter_var($post['dateEnd'], FILTER_SANITIZE_STRING));
				$intQty = stripslashes(filter_var($post['intQty'], FILTER_SANITIZE_STRING));
			}
				
			$data = array(
					'strItemCode' => $strItemCode,
					'strTitle' => $strTitle,
					'strDescription' => $strDescription,
					'intPoints' => $intPoints,
					'strImgLink' => $strImgLink,
					'dateStart' => $dateStart,
					'dateEnd' => $dateEnd,
					'intQty' => $intQty,
					'intDisabled' => 0,
					'strCreatedby'=>$this->session->userdata('intID'),
					'dateCreatedDate'=>date('Y-m-d H:i:s'),
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			$this->db->where(array('intID'=>$intID));
			$this->db->insert('jtn_exchange_item', $data);
			
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function get_exchange_item($post){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
			}
			$query = $this->db->where(array('intID'=>$intID));
			$query = $this->db->get('jtn_exchange_item')->result_array();
			
			if($query['intID']==""){
				return 0;
			}else{
				return $query;
			}
		}
	}
?>